<?php

class spAddToListComboAndText extends spAddToListBase
{
	private $data;

	public function __construct( $data=null )
	{
		$this->data = $data;
		parent::__construct();
		
		parent::setClass( "spAddToListBase spAddToListComboAndText" );
		
		// this is where we insert already predefined items
		if ( isset($data["items"]) && count($data["items"]) )
		{
			$insert_here = $this->find("insert_here");
			
			foreach ( $data["items"] as $item )
			{
				$insert_here->addChild( $this->createCloneableContainer( array(
					"selected_value"=>$item["field"],
					"map"=>$item["map"]
				)));
			}
		}		
	}
	
	protected function createInsertHtml( $param=array() )
	{
		$data = $this->data;
		
		$selected_value = isset($param["selected_value"])?$param["selected_value"]:"";
		
		$name 		= isset($data["name"])?$data["name"]:"";
		
		$input_class 	= isset($data["class"])?$data["class"]:"";
		$map 			= isset($param["map"])?$param["map"]:"";
		
		// FIXME: remove wordpress code and find a way to create the path to the image
		$img = get_option('home').'/wp-content/plugins/gym/sigmaphp/html/extended/dragbar_gray.png';
		$i = new spImage(array("src"=>$img));
		$i->addAttr( "align", "top" );
		
		$combobox = new spCombobox( array( 
			"name"			=>$data["name"]."_field[]", 
			"list"			=>$data["list"],
			"selected_value"=>$selected_value 
		));

		$table = new spTableExt;
		$table->addRowChilds( array(
			$i,
			$combobox,
			new spInputText( array( "class"=>$input_class, "name"=>$name."_map[]", "value"=>$map ) )
		));

		return $table;		
	}	
}

?>